package com.yzy.soft.system.freemarker.template;

import com.yzy.soft.system.freemarker.JavaFileController;
import com.yzy.soft.system.freemarker.TemplateKernel;
import com.yzy.soft.system.freemarker.FileInfo;
import com.yzy.soft.system.freemarker.database.Table;
import com.yzy.soft.system.freemarker.DBInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class TemplateRepository extends TemplateKernel {
    private final static Logger logger= LoggerFactory.getLogger(TemplateDao.class);

    @Override
    public File generateFileType(FileInfo fileInfo, Table table, DBInfo dbInfo) throws Exception {
        JavaFileController javaFile=(JavaFileController)fileInfo;
        final String suffix = "Repository.java";
        final String templateName = "Repository.ftl";
        File file = new File(fileInfo.getDiskPath());
        if (!file.exists()) {
            file.createNewFile();
        }else{
            file.deleteOnExit();
        }
        Map<String, Object> dataMap = new HashMap<String, Object>();
            String path = fileInfo.getDiskPath() +javaFile.getFilename()+ javaFile.getSuffix();
            File controllerFile = new File(path);
        logger.info("TemplateRepository path:"+path);
            generateFileByTemplate(templateName, controllerFile,fileInfo, dataMap);
        return controllerFile;
    }



}
